package com.dower.clothing.controller;

import java.util.List;

import com.dower.common.annotation.Log;
import com.dower.common.core.controller.BaseController;
import com.dower.common.core.domain.AjaxResult;
import com.dower.common.core.page.TableDataInfo;
import com.dower.common.enums.BusinessType;
import com.dower.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.dower.clothing.domain.ClProduct;
import com.dower.clothing.service.IClProductService;

/**
 * 衣服定制订单Controller
 * 
 * @author dower
 * @date 2020-08-31
 */
@Controller
@RequestMapping("/clothing/order")
public class ClProductController extends BaseController
{
    private String prefix = "clothing/order";

    @Autowired
    private IClProductService clProductService;

    @RequiresPermissions("clothing:order:view")
    @GetMapping()
    public String order()
    {
        return prefix + "/order";
    }

    /**
     * 查询衣服定制订单列表
     */
    @RequiresPermissions("clothing:order:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ClProduct clProduct)
    {
        startPage();
        List<ClProduct> list = clProductService.selectClProductList(clProduct);
        return getDataTable(list);
    }

    /**
     * 导出衣服定制订单列表
     */
    @RequiresPermissions("clothing:order:export")
    @Log(title = "衣服定制订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ClProduct clProduct)
    {
        List<ClProduct> list = clProductService.selectClProductList(clProduct);
        ExcelUtil<ClProduct> util = new ExcelUtil<ClProduct>(ClProduct.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 新增衣服定制订单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存衣服定制订单
     */
    @RequiresPermissions("clothing:order:add")
    @Log(title = "衣服定制订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ClProduct clProduct)
    {
        return toAjax(clProductService.insertClProduct(clProduct));
    }

    /**
     * 修改衣服定制订单
     */
    @GetMapping("/edit/{numId}")
    public String edit(@PathVariable("numId") Long numId, ModelMap mmap)
    {
        ClProduct clProduct = clProductService.selectClProductById(numId);
        mmap.put("clProduct", clProduct);
        return prefix + "/edit";
    }

    /**
     * 修改保存衣服定制订单
     */
    @RequiresPermissions("clothing:order:edit")
    @Log(title = "衣服定制订单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ClProduct clProduct)
    {
        return toAjax(clProductService.updateClProduct(clProduct));
    }

    /**
     * 删除衣服定制订单
     */
    @RequiresPermissions("clothing:order:remove")
    @Log(title = "衣服定制订单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(clProductService.deleteClProductByIds(ids));
    }
}
